package hot;

import java.util.HashSet;
import java.util.Set;

/**
 * @author lakersUp
 * @Classname
 * @Description
 * @Date 2022/3/7 10:17
 * @Version 1.0
 */
public class Hot3lengthOfLongestSubstring {
    public int lengthOfLongestSubstring(String s) {
        if(s.length()==0){
            return 0;
        }
        int l=0,r=0,max=0;
        Set<Character> set=new HashSet();
        while(r<s.length()){
            while (set.contains(s.charAt(r))){
                set.remove(s.charAt(l++));
            }
            max=Math.max(max,(r-l+1));
            set.add(s.charAt(r++));
        }
        return max;
    }
}
